//
//  UIBarButtonItem+Extension.swift
//  WeiBo
//
//  Created by Feng on 2017/6/4.
//  Copyright © 2017年 feng. All rights reserved.
//

import UIKit

extension UIBarButtonItem
{
    //使用便利构造函数,对init进行扩展
    convenience init(title: String?, imageName: String? = nil, target: Any?, action: Selector?)
    {
        self.init()
        
        let button = UIButton()
        
        button.setTitle(title, for: .normal)
        button.setTitleColor(UIColor.lightGray, for: .normal)
        button.setTitleColor(UIColor.orange, for: .highlighted)
        button.titleLabel?.font = UIFont.systemFont(ofSize: 15)
        
        button.addTarget(target, action: action!, for: .touchUpInside)
        
        //设置图片
        if(imageName != nil)
        {
            button.setImage(UIImage(named:imageName!), for: .normal)
        }
        
        //设置大小
        button.sizeToFit()
        
        self.customView = button
    }
}
